﻿using System.Collections.ObjectModel;
using StockModel;
using Utils;

namespace TimeBarPlugin.Realtime
{
	internal class DataLoaderMessageProcessor : MessageProcessor
	{
		#region Attributes

		private readonly ObservableCollection<Quotation> _data;

		#endregion

		#region Public Methods

		public DataLoaderMessageProcessor(ObservableCollection<Quotation> data) : base("Full Day Strategy Plugin 2 Data Loader Decoupler")
		{
			_data = data;
		}

		protected override void ProcessMessage()
		{
			if (base.CurrentMessage.Type == LoaderMessageType.AddQuotation)
			{
				AddQuotationMessage addMessage = (AddQuotationMessage)base.CurrentMessage;
				_data.Add(addMessage.Quotation);
			}
			else if (base.CurrentMessage.Type == LoaderMessageType.ClearQuotations)
			{
				_data.Clear();
			}
		}

		#endregion
	}
}
